package top.hkyzf.study.leetcode.array;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2020-12-17 18:27
 */
public class 两数之和_1 {
    public int[] twoSum1(int[] nums, int target) {
        for(int i=0; i<nums.length; i++) {
            for(int j=i+1; j<nums.length; j++) {
                if(nums[i] + nums[j] == target)
                {
                    return new int[] {i,j};
                }
            }
        }
        System.out.printf("未找到相加等于%d的下标", target);
        System.out.println();
        return null;
    }

    /**
     * 2022-02-11 第二次刷
     * @param nums 给定的整数数组
     * @param target 整数目标值
     * @return 和为目标值的两个整数的下标
     */
    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return null;
    }

    @Test
    public void testTwoSum() {
        int[] nums = new int[] {2,7,11,15};
        int target = 9;
        int [] result = twoSum(nums, target);
        System.out.println(result[0] + "=-=-=" + result[1]);
    }
}
